1. Field of the Invention
The present invention relates to dynamic compiler programs, dynamic compiling methods, and dynamic compiling devices. More particularly, the present invention relates to a dynamic compiler program, a dynamic compiling method, and a dynamic compiling device for reusing a compiled partial program having undergone adaptive optimization.
2. Description of the Related Art
Recently, dynamic compilers such as just-in-time (JIT) compliers have been used in, for example, environments for executing Java® programs. In the middle of execution of a program such as a Java® application, when a part of the program having not been compiled needs to be executed, a dynamic compiler compiles a partial program that is the part of the program to be executed. In this arrangement, while a delay in starting up a program in a case where the whole program is first compiled is prevented, execution of the program can be performed rapidly as compared with interpreter execution.
In order to execute a program more rapidly, when compiling a partial program, a dynamic compiler acquires execution status information that is the status information of an environment for executing a program and generates a compiled executable instruction stream by performing optimization to adapt to the status of an execution environment indicated by the execution status information. Execution status information referred to by a dynamic compiler for optimization includes, for example, information on whether a class has been loaded and profile data at the time of executing a program. Such optimization is called adaptive optimization (refer to Suganuma, et al., “A Dynamic Optimization Framework for a Java just-in-time Compiler”, In Proceedings of the ACM SIG-PLAN Conference on Object-Oriented Programming, Systems, Languages & Applications, pp. 180-194, October 2001).
An executable instruction stream generated by a dynamic compiler such as a JIT compiler compiling a partial program in the aforementioned manner is available while a compiled process is operating. Thus, a dynamic compiler compiles the partial program every time the same Java program is executed. Such a situation occurs, for example, when the same Java program is executed multiple times in the same machine or when a plurality of guest virtual machines execute the same Java program in a virtualization environment.
Hitherto, a technique for enabling, by storing ahead-of-time (AOT) code compiled by AOT compilation in a permanent cache, sharing of the compiled AOT code among Java® virtual machines has been disclosed as a technique for avoiding duplicate compilation of a partial program included in a Java program (refer to Pilkington, et al., “Enhance performance with class sharing,” Sep. 30, 2008, developerWorks Japan).
Moreover, a technique is disclosed in which a virtual machine includes a code cache as a storage area with a limited capacity for native code and a JIT compiler that compiles byte code to native code that can be executed directly by the virtual machine in execution of the byte code, stores the native code in the code cache, and then executes the native code. The virtual machine further includes a search table for searching for information used to determine whether compilation has been done and the address of the compiled native code on the basis of the address of the byte code (refer to Japanese Patent No. 3808755 [JP2003140909]).
In Pilkington, the AOT code stored in the permanent cache is a native code variant of a Java® method generated by AOT compilation. Unlike JIT compilation, AOT compilation does not adopt adaptive optimization adapted to the result of dynamic analysis of a Java method that is being executed. Thus, although the time necessary for compilation is reduced by sharing of the AOT code, the execution speed of the shared AOT code is low.
On the other hand, in Japanese Patent No. 3808755, the native code stored in the code cache is generated by JIT compilation. However, Japanese Patent No. 3808755 does not describe optimization, including adaptive optimization, for improving the execution speed of a program, and the native code stored in the code cache is native code having not undergone optimization. Thus, as is the case with the technique in Pilkington, the execution speed of the native code to be reused in Japanese Patent No. 3808755 is low.
Accordingly, duplicate compilation of a partial program included in a Java program needs to be avoided, and the program needs to be executed rapidly. However, even in a case where an executable instruction stream generated by the application of adaptive optimization is simply stored in a cache as shared code, since optimization is performed to adapt to the status of an execution environment indicated by the value of current execution status information in adaptive optimization, as described above, when the value of current execution status information differs from the value of execution status information at the time of reuse, the availability of the shared code is unknown, and eventually, the shared code cannot be used. In this regard, JP2005215884 describes that, when compilation has been performed so as to be optimized to a status different from the status of the current execution environment, it is determined that recompilation is necessary, and recompilation is performed.
However, in an arrangement in which, only in a case where the value of execution status information at the time of compilation is the same as the value of execution status information at the time of reuse, a compiled executable instruction stream is used, as shown in JP2005215884, the reusability is low, and thus, advantageous effects achieved by the reuse of compiled code can seldom be expected.
In this case, a method (specialization) for specializing a part of a program to processing performed when a variable referred to by the program takes a specific value is proposed as a method for optimization. For example, a method for determining, regarding each method in a program, whether the value of a variable takes a predetermined value every time the method is called and performing processing by branching to a specialized instruction stream or a non-specialized instruction stream in a manner that depends on the determination result is proposed (refer to JP2002259135). Thus, the aforementioned problem is solved by using specialization as a method for optimization. However, the problem of reuse of native code generated by the application of adaptive optimization is still unsolved.